import Vue from 'vue'
let map = new WeakMap();
const ob = new ResizeObserver((entries) => {
  for (const entry of entries) {
    let handler = map.get(entry.target);
    // console.log(entry);
    if (handler) {
      handler({
        width: entry.borderBoxSise ? entry.borderBoxSise[0].inlineSize : null,
        height: entry.borderBoxSise ? entry.borderBoxSise[0].blockSize : null,
        target: entry.target,
      });
    }
  }
});

const vResize = {
  bind: (el, binding) => {
    map.set(el, binding.value);
    ob.observe(el);
  },
  unbind: (el) => {
    ob.unobserve(el);
  },
};

Vue.directive("dyxResize", vResize);
